<div class="form">

<?php
    Yii::app()->clientScript->registerCoreScript('jquery');
    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/modal/dxtmodal.js', CClientScript::POS_HEAD);
    Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/modal/modal.css');
    /**
     * @var $form CActiveForm
     */
    $form=$this->beginWidget('CActiveForm', array(
	'id'=>'guitar-class-form',
	'enableAjaxValidation'=>false,
)); ?>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'facility_id'); ?>
		<?php echo $form->listBox($model,'facility_id',GuitarClass::listFacilities(),array('size'=>1)); ?>
		<?php echo $form->error($model,'facility_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>
    <div class="row">
        <?php echo $form->labelEx($model,'training_id'); ?>
        <?php echo $form->listBox($model,'training_id',GuitarClass::listTraining(),array('size'=>1)); ?>
        <?php echo $form->error($model,'training_id'); ?>
    </div>
	<div class="row">
		<?php echo $form->labelEx($model,'body'); ?>
		<?php
        $this->widget('application.extensions.ckeditor.CKEditor', array(
            'model'=>$model,
            'attribute'=>'body',
            'language'=>'vi',
            'editorTemplate'=>'basic',
        ));
        ?>
		<?php echo $form->error($model,'body'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'start_time'); ?>
		<?php
		//echo $form->textField($model,'start_time');
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name'=>'GuitarClass[start_time]',
            'language'=>'vi',
            'value'=>date('d/m/Y',$model->start_time ? $model->start_time : time()),
            // additional javascript options for the date picker plugin
            'options'=>array(
                'showAnim'=>'fold',
            ),
            'htmlOptions'=>array(
                'style'=>'height:20px;'
            ),
        ));
        ?>
		<?php echo $form->error($model,'start_time'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'end_time'); ?>
		<?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name'=>'GuitarClass[end_time]',
            'language'=>'vi',
            'options'=>array(
                'showAnim'=>'fold',
            ),
            'value'=>date('d/m/Y',$model->end_time ? $model->end_time : time()),
            'htmlOptions'=>array(
                'style'=>'height:20px;'
            ),
        ));
        ?>
		<?php echo $form->error($model,'end_time'); ?>
	</div>
    <div class="row">
        Thời gian học:
        <div id="lstime">
            <?php
            if($model->classtime){
                $out = '<ul>';
                foreach($model->classtime as $tk){
                    $out .="<li class='time_".$tk->id."'><span>".($tk->day == 8 ? 'CN' : "Thứ {$tk->day}").", từ ".date("H:i",$tk->start_time)." đến ".date("H:i",$tk->end_time)."</span> ".CHtml::ajaxLink('Xóa',$this->createUrl('deltime',array('id'=>$tk->id)),array('success'=>'js:function(data){
                    if(data.success == 1){
                        $(".time_"+data.id).remove();
                var remove = function () {
                    $(this).remove();
                };

                $("#dxt-mask").fadeOut(remove);
                $("#dxt-box").fadeOut(remove);
                    }
                    }'))." | ".CHtml::link('Sửa',$this->createUrl('/admin/classtime/update',array('id'=>$tk->id)),array('class'=>'modal'))."</li>";
                }
                $out .= '</ul>';
                echo $out;
            }else{
                echo '<ul></ul>';
            }

            ?>
        </div>
        <button id="addtime">Thêm thời gian</button>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'status'); ?>
        <?php echo $form->listBox($model,'status',array(1=>'Hoạt động',2=>'Không hoạt động'),array('size'=>1)); ?>
        <?php echo $form->error($model,'status'); ?>
    </div>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Tạo' : 'Lưu'); ?>
	</div>

<?php $this->endWidget(); ?>
    <script type="text/javascript">
        $(function(){
           $('#addtime').dxtmodal({width:220,height:250,title:'Thêm thời gian học',ajax:{url:'/admin/classtime/create'}});
           $('.modal').dxtmodal({width:220,height:250,title:'Sửa thời gian học'});
        });
    </script>

</div><!-- form -->